package com.myqf.d7_日期类_druid连接池.jdbc连接池.pool连接池测试;


import com.myqf.d7_日期类_druid连接池.jdbc连接池.ConnectionPool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 作者：黎杭
 * 日期：2020/2/18
 */
public class Test {
    public static void main(String[] args) throws Exception {

        Connection connection = ConnectionPool.getConnection();// s
        String sql = "select * from user";// 注意：珍惜使用*的sql语句。因为在后面，禁止再出现*，出现*罚款200起
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();// 执行查询语句
        while (resultSet.next()) {
            int userId = resultSet.getInt(1);
            String name = resultSet.getString(2);
            int age = resultSet.getInt(3);
            String phone = resultSet.getString(4);
            String pwd = resultSet.getString(5);
            System.err.println(userId);
            System.err.println(name);
            System.err.println(age);
            System.err.println(phone);
            System.err.println(pwd);
        }
        // 用完之后，把连接对象放回池子，至于关闭与否，不管，池子自行维护
        ConnectionPool.backConnection(connection);
    }
}
